package work.mediway.mdm.core.enums;

import java.util.HashMap;
import java.util.Map;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * 状态
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/12/29
 */
public enum StatusEditEnum {

    /**
     * 新增
     */
    STATUS_INSERT("A", "新增"),
    /**
     * 更新
     */
    STATUS_UPDATE("U", "更新"),
    /**
     * 删除
     */
    STATUS_DELETE("D", "删除"),
    /**
     * 新增
     */
    STATUS_INSERT_FULL("INSERT", "新增"),
    /**
     * 更新
     */
    STATUS_UPDATE_FULL("UPDATE", "更新"),
    /**
     * 删除
     */
    STATUS_DELETE_FULL("DELETE", "删除")


    // ======================================================================= //
    ;

    public static Map<String, String> map = new HashMap<>();

    public static Map<String, String> map_ = new HashMap<>();

    static {
        StatusEditEnum[] values = StatusEditEnum.values();
        if (values.length > 0) {
            for (StatusEditEnum categoryEnum : values) {
                map.put(categoryEnum.getStatusCode(), categoryEnum.getStatusDesc());
            }
        }
        map_.put(STATUS_INSERT_FULL.statusCode, STATUS_INSERT.statusCode);
        map_.put(STATUS_UPDATE_FULL.statusCode, STATUS_UPDATE.statusCode);
        map_.put(STATUS_DELETE_FULL.statusCode, STATUS_DELETE.statusCode);
    }

    public static StatusEditEnum getEnum(String code) {
        for (String key : map_.keySet()) {
            if (StrUtil.equalsIgnoreCase(key, code)) {
                return get(map_.get(key));
            }
        }
        return null;
    }

    public static StatusEditEnum get(String statusCode) {
        StatusEditEnum[] values = StatusEditEnum.values();
        for (StatusEditEnum value : values) {
            if (StrUtil.equalsIgnoreCase(value.getStatusCode(), statusCode)) {
                return value;
            }
        }
        return null;
    }

    StatusEditEnum(String statusCode, String statusDesc) {
        this.statusCode = statusCode;
        this.statusDesc = statusDesc;
    }

    /**
     * Code
     */
    @Setter
    @Getter
    private String statusCode;

    /**
     * Desc
     */
    @Setter
    @Getter
    private String statusDesc;

}
